// 首页轮播
if ($(".bannerlunbox  .bd li").size() >= 1) {
  jQuery(".bannerlunbox").slide({
    mainCell: ".bd ul",
    titCell: ".hd ul",
    effect: "leftLoop",
    autoPlay: true,
    trigger: "mouseover",
    easing: "swing",
    interTime: "6000",
    mouseOverStop: "true",
    pnLoop: "true",
    autoPage: true,
  });
}

//详情H3
if ($(".news_center.h3box>h3").size() >= 1) {
  $(".news_center.h3box>h3").each(function () {
    $(this).html("<span>" + $(this).html() + "</span>");
  });
}
//页面左右划动
function HomeScroll(a, b) {
  function g() {
    var g = $(window).scrollLeft(),
      h = $(window).scrollTop(),
      i = $(document).height(),
      j = $(window).height(),
      k = c.height(),
      l = d.height(),
      m = k > l ? f : e,
      n = k > l ? d : c,
      o = k > l ? c.offset().left + c.outerWidth(!0) - g : d.offset().left - c.outerWidth(!0) - g,
      p = k > l ? l : k,
      q = k > l ? k : l,
      r = parseInt(q - j) - parseInt(p - j);
    $(a + "," + b).removeAttr("style"), j > i || p > q || m > h || p - j + m >= h ? n.removeAttr("style") : (j > p && h - m >= r) || (p > j && h - m >= q - j) ? n.attr("style", "margin-top:" + r + "px;") : n.attr("style", "_margin-top:" + (h - m) + "px;position:fixed;left:" + o + "px;" + (j > p ? "top" : "bottom") + ":0;");
  }
  if ($(a).length > 0 && $(b).length > 0) {
    var c = $(a),
      d = $(b),
      e = c.offset().top,
      f = d.offset().top;
    $(window).resize(g).scroll(g).trigger("resize");
  }
}
HomeScroll(" .ContL", ".ContR");
//点击跳转大图
$(" .news_center p > img ").click(function () {
  var imgurl = $(this).attr("src");
  if ($("#abigimg").length == 0) {
    var a = document.createElement("a");
    a.setAttribute("id", "abigimg");
    a.setAttribute("href", imgurl);
    a.setAttribute("target", "_blank");
    document.body.appendChild(a);
  } else {
    $("#abigimg").attr("href", imgurl);
  }
  document.getElementById("abigimg").click();
});

function swich(e, f) {
  e.mouseenter(function () {
    $(this).addClass("on").siblings().removeClass("on");
    if (f) {
      f.eq($(this).index()).show().siblings().stop().hide();
    }
  });
}
swich($(".Ritem2 .list ul li ")); //本类排行右侧的
swich($(".Mindex6 .item ul li ")); //首页排行榜

// 切换hover
$(".switch_hover .switchlabe .lab").mouseenter(function () {
  $(this).addClass("on").siblings().removeClass("on");
  var i = $(this).index();
  $(this).parents(".switch_hover").find(".switchbox .switchitem ").eq(i).show().siblings().hide();
  $(this).parents(".sswitch_hover").find(".switchmore a").eq(i).show().siblings().hide();
  $(window).trigger("scroll");
});
// 切换click
$(".switch_ck .switchlabe .lab").click(function () {
  $(this).addClass("on").siblings().removeClass("on");
  var i = $(this).index();
  $(this).parents(".switch_ck").find(".switchbox .switchitem ").eq(i).show().siblings().hide();
  $(this).parents(".sswitch_ck").find(".switchmore a").eq(i).show().siblings().hide();
  $(window).trigger("scroll");
});

//落地页面截图
$(window).load(function () {
  if ($(" .Min3 .lubox .bd li").size() > 1) {
    var w = $(" .Min3 .lubox .bd li").eq(0).find("img").width();
    var h = $(" .Min3 .lubox .bd li").eq(0).find("img").height();
    if (w < h) {
      $(" .Min3 .lubox").addClass("lunbox_h");
    } else {
      $(" .Min3 .lubox").addClass("lunbox_w");
    }
    jQuery(" .Min3 .lubox").slide({
      mainCell: ".bd ul",
      autoPage: "true",
      effect: "leftLoop",
      vis: 3,
    });
    resizeImg(" .Min3 .lubox .bd li");
  }
});
//图片放大切换效果
function resizeImg(objname) {
  var obj = $(objname);
  var imgbox = obj.parents(".lubox");
  var imgarry = [];
  //存储图片
  var len = obj.length;
  var Img = imgbox.find("img");
  var realwd, realhd;
  var imgo = new Image();
  imgo.src = Img.eq(0).attr("src");
  imgo.onload = function () {
    for (var i = 0; i < len; i++) {
      realwd = imgo.width;
      realhd = imgo.height;
      var imgdx = new Object();
      imgdx.rWidth = realwd;
      imgdx.rHeight = realhd > parseInt($(window).height()) ? parseInt($(window).height()) : realhd;
      imgdx.imgsrc = Img.eq(i).attr("src");
      imgarry.push(imgdx);
    }
  };
  imgo.src = Img.eq(0).attr("src");

  obj.on("click", function () {
    var html = "";
    var str = "";
    var current = $(this).index();
    $.each(imgarry, function (n, v) {
      if (n == current) {
        str = "<img src='" + v.imgsrc + "' class='current'>";
      } else {
        str = "<img src='" + v.imgsrc + "'>";
      }
      html = html + str;
    });
    $("body > .bg").remove();
    $("body > .m-showbox").remove();
    $("body").append('<div class="bg"></div><div class="close-showbox"></div><div class="m-showbox"> <div class="inner-box"><span class="prev"></span> ' + html + '<span class="next"></span></div>');
    $(".bg").show();
    $("body").css("overflow", "hidden");
    $(".m-showbox").fadeIn();
    if (len < 2) {
      $(".prev,.next").hide();
    }
    function showCurrent(current) {
      $(".m-showbox").css({
        "margin-top": -imgarry[current].rHeight / 2,
        "margin-left": -imgarry[current].rWidth / 2,
        height: imgarry[current].rHeight,
        width: imgarry[current].rWidth,
      });
      $(".m-showbox .inner-box").css({
        height: imgarry[current].rHeight,
        width: imgarry[current].rWidth,
      });
    }
    showCurrent(current);
    //上一张
    $(".m-showbox .prev").on("click", function () {
      if (current == 0) {
        current = len - 1;
      } else {
        current = current - 1;
      }
      $(".m-showbox img").eq(current).addClass("current").siblings().removeClass("current");
      showCurrent(current);
    });

    //下一张
    $(".m-showbox .next").on("click", function () {
      if (current == len - 1) {
        current = 0;
      } else {
        current = current + 1;
      }
      $(".m-showbox img").eq(current).addClass("current").siblings().removeClass("current");
      showCurrent(current);
    });
  });
  $(document).on("click", ".close-showbox,.bg", function () {
    $(".m-showbox,.bg,.close-showbox").remove();
    $("body").css("overflow", "auto");
  });
}

// 排行榜导航切换
$(".ranking  .ranknav li .bt").click(function () {
  $(this).parents("li").addClass("on").siblings().removeClass("on");
});

$(".index-zt-slider1").slide({ mainCell: ".slidesjs-container1 ul", autoPage: true, effect: "left", scroll: 1, vis: 6 });
$(".index-zt-slider2").slide({ mainCell: ".slidesjs-container2 ul", autoPage: true, effect: "left", scroll: 1, vis: 6 });
